package com.testin.utils;


import java.io.FileNotFoundException;
import java.net.URL;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;

public class ConfigurationUtils {
	
	static String DB_DRIVER;
	static String DB_URL;
	static String DB_USERNAME;
	static String DB_PASSWORD;
	static String SMTP_HOST;
	static String MAIL_FROM;
	static String ERROR_CONTENT;
	static String MAIL_USER;
	static String MAIL_PASSWORD;
	static String MSG_CONTENT;
	static String SUBJECT;
	
	
	static  {
		 try {
			DB_DRIVER=getConfigString("driverClassName");
			DB_URL=ConfigurationUtils.getConfigString("urlAdd");
			DB_USERNAME=ConfigurationUtils.getConfigString("username");
			DB_PASSWORD=ConfigurationUtils.getConfigString("password");
			SMTP_HOST=ConfigurationUtils.getConfigString("smtpHost");
			MAIL_FROM=ConfigurationUtils.getConfigString("mailFrom");
			ERROR_CONTENT=ConfigurationUtils.getConfigString("errorContent");
			MAIL_USER=ConfigurationUtils.getConfigString("mailUser");
			MAIL_PASSWORD=ConfigurationUtils.getConfigString("mailPassword");
			MSG_CONTENT=ConfigurationUtils.getConfigString("msgContent");
			SUBJECT=ConfigurationUtils.getConfigString("subject");
			
			
			
		} catch (ConfigurationException e) {
			e.printStackTrace();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		 
	}

	
	public static String getConfigString(String key)throws org.apache.commons.configuration.ConfigurationException, FileNotFoundException,Exception{
		URL url = ConfigurationUtils.class.getResource("/app.properties");
		Configuration  config = new PropertiesConfiguration(url.getPath());
		
		if (key == null || key.equals("") || key.equals("null")) {
            return "";
        }
        String result = "";
        try {
            result = config.getString(key);
        } catch (Exception e) {
            throw e;
        }
        return result;
		
	}

}
